var app = getApp(),
$ = require("../../utils/httpHelper.js");
Page({
  data: {
    nav1: [{ name: "我的代理", types: 'agent' }, { name: "我的员工", types:'staff'}],
    nav2: [{ name: "我的员工", types: 'staff' }],
    nav3: [{ name: "我的用户", types: 'member' }],
    is1: false,
    is2: false,
    is3: false,
    types:'',
    currnav:0,
    page: 1,
    pagesize: 7,
    totalpage: 0,//最大页数
    height: 0,
    nomore: false,
    fanslist:[]
  },
  onLoad: function (options) {
     var that=this;
     wx.getSystemInfo({
       success: function (res) {
         that.setData({ 
           height: res.windowHeight
         })
       }
     })
     let memberType = wx.getStorageSync('member_type')
     if (memberType == 4){
       this.setData({
         is1:true,
         is2:false,
         is3:false,
         types:'agent'
       })
     } else if (memberType == 6 || memberType == 31){
       this.setData({
         is1: false,
         is2: true,
         is3: false,
         types:'staff '
       })
     } else if (memberType == 8 || memberType == 16 || memberType == 24 || memberType == 30){
       this.setData({
         is1: false,
         is2: false,
         is3: true,
         types:'member '
       })
     }
    this.getData()
  },
  getData(){
    let par = {
      rd_session: app.globalData.userInfo.rd_session,
      types: this.data.types,
      page:this.data.page,
      pagesize:this.data.pagesize,
    }
    $.httpPost("fans", par, (data, err) => {
      this.setData({
        fanslist:data.data.list,
        totalpage: data.data.total_page
      })
    })
  },
  currrnav:function(e){
    console.log(e)
    var currnav = e.currentTarget.dataset.index
    let types = e.currentTarget.dataset.types
    this.setData({
      currnav: currnav,
      page: 1,
      types:types
    })
    this.getData()
  },
  //滑动到底部 上拉加载
  scrollBottom: function () {
    this.data.page++
    if (this.data.page > this.data.totalpage) {
      this.setData({
        nomore: false
      })
    } else {
      let params = {
        rd_session: app.globalData.userInfo.rd_session,
        page: this.data.page,
        pagesize: this.data.pagesize,
        types: this.data.types
      }
      $.httpPost("fans", params, (data, err) => {
        let arr = this.data.fanslist;
        for (let item of data.data.list) {
          arr.push(item);
        }
        this.setData({
          fanslist: arr
        })
      })
    }

  },
})